package com.aaa.service.impl;

import com.aaa.common.domain.ContractReminder;
import com.aaa.common.query.PageQuery;
import com.aaa.common.query.ReminderContractConditionalQuery;
import com.aaa.common.result.Result;
import com.aaa.mapper.ContractReminderMapper;
import com.aaa.service.ContractReminderService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 宋文森
 * @Date: 2021/02/21/16:11
 * @Description: 合同到期提醒业务服务接口实现类
 */
@Service
public class ContractReminderServiceImpl implements ContractReminderService {

    @Autowired
    private ContractReminderMapper contractReminderMapper;

    /**
     * 查询所有租出合同相关信息
     * @param pageQuery
     * @return
     */
    public Result listRentOutContractReminder(PageQuery pageQuery) {
        Page<ContractReminder> contractReminderPage = new Page<>(pageQuery.getCurrentPage(),pageQuery.getPageCount());
        Page<ContractReminder> contractReminders = contractReminderMapper.listRentOutContractReminder(contractReminderPage);
        if (contractReminders!=null){
            return Result.success(contractReminders);
        }
        return Result.error("合同到期提醒查询失败或没有结果");
    }

    /**
     * 条件查询租出合同相关信息
     * @param reminderContractConditionalQuery
     * @return
     */
    public Result RentOutContractConditionalQuery(ReminderContractConditionalQuery reminderContractConditionalQuery) {
        Page<ContractReminder> contractReminderPage = new Page<>(reminderContractConditionalQuery.getCurrentPage(),reminderContractConditionalQuery.getPageCount());
        Page<ContractReminder> contractReminders = contractReminderMapper.RentOutContractConditionalQuery(contractReminderPage,  reminderContractConditionalQuery.getSelectDate(), reminderContractConditionalQuery.getCompanyId());
        if (contractReminders!=null){
            return Result.success(contractReminders);
        }
        return Result.error("合同到期提醒条件查询失败或没有结果");
    }

    /**
     * 条件查询时的下拉框查询（产证所属）
     * @return
     */
    public Result listCompanyName() {
        List<ContractReminder> contractReminders = contractReminderMapper.listCompanyName();
        if (contractReminders.size()>0){
            return Result.success(contractReminders);
        }
        return Result.error("查询产证所属失败");
    }

    /**
     * 租入合同到期提醒的查询所有
     * @param pageQuery
     * @return
     */
    public Result listRentInContract(PageQuery pageQuery) {
        Page<ContractReminder> contractReminderPage = new Page<>(pageQuery.getCurrentPage(),pageQuery.getPageCount());
        Page<ContractReminder> contractReminders = contractReminderMapper.listRentInContract(contractReminderPage);
        if (contractReminders!=null){
            return Result.success(contractReminders);
        }
        return Result.error("合同到期提醒查询失败或没有结果");
    }

    /**
     * 租入合同到期提醒的条件查询
     * @param reminderContractConditionalQuery
     * @return
     */
    public Result RentInContractConditionalQuery(ReminderContractConditionalQuery reminderContractConditionalQuery) {
        Page<ContractReminder> contractReminderPage = new Page<>(reminderContractConditionalQuery.getCurrentPage(),reminderContractConditionalQuery.getPageCount());
        Page<ContractReminder> contractReminders = contractReminderMapper.RentInContractConditionalQuery(contractReminderPage, reminderContractConditionalQuery.getCompanyName(), reminderContractConditionalQuery.getSelectDate(), reminderContractConditionalQuery.getLessor());
        if (contractReminders!=null){
            return Result.success(contractReminders);
        }
        return Result.error("合同到期提醒条件查询失败或没有结果");
    }

    /**
     * 租入合同到期提醒条件查询时的下拉框查询（出租方）
     * @return
     */
    public Result listLessor() {
        List<ContractReminder> contractReminders = contractReminderMapper.listLessor();
        if (contractReminders.size()>0){
            return Result.success(contractReminders);
        }
        return Result.error("查询产证所属失败");
    }

}
